#!/usr/bin/python

import time, sys
from math import sqrt, ceil, floor

""" 
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?
"""
def isprime(num):
    ans = True
    if num <= 1:
        return False
    if num % 2 == 0:
        return False
    for n in xrange(3, int(ceil(sqrt(num)))+1, 2):
        if num % n == 0:
            ans = False
            break

    return ans


def main():
    start = time.time()
    
    x = 13195
    for n in xrange(1, int(sqrt(x))):
        if isprime(n) and x % n == 0:
            print n,
    print 'is the solution'
    
    x = 600851475143
    for n in xrange(1, int(sqrt(x))):
        if x % n == 0 and isprime(n):
            print n,
    print 'is the solution'
    
    print '{0:.2f} s'.format(time.time() - start)        

# solution 1: 6857 in 2.48 s  tested -> if isprime(n) and x % n == 0:
# solution 2: 6857 in 0.26 s  tested first for factor then it the factor is prime

if __name__ == '__main__':
  main()
